package edu.ccut.titan.component.impl.directory;

import java.util.Enumeration;

import org.osgi.framework.Bundle;

import edu.ccut.titan.component.ComponentFactory;
import edu.ccut.titan.component.IBundleInfo;
import edu.ccut.titan.component.TitanComponentException;

public class TitanBaseComponentDirectoryInfo extends AbstractDirectoryInfo {

	private static final String TITAN_BASE_COMPONENT_FILE_POSTFIX = ".component.xml";

	public TitanBaseComponentDirectoryInfo() {
		super(TITAN_DIRECTORY_TYPE_COMPONENT);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void load(Bundle bundle, IBundleInfo bundleInfo)
			throws TitanComponentException {

		Enumeration<String> componentFiles = bundle.getEntryPaths(super
				.getDirectoryPath());

		while (componentFiles.hasMoreElements()) {
			String actionFile = componentFiles.nextElement();

			if (actionFile != null
					&& actionFile.endsWith(TITAN_BASE_COMPONENT_FILE_POSTFIX)) {
				bundleInfo.addComponentInfos(ComponentFactory
						.getComponentInfos(bundle, actionFile));

			}
		}
	}
}
